/**
 * https://leetcode.cn/problems/binary-search/
 */
function search(nums: number[], target: number): number {
  let ans = -1;

  let start = 0;
  let end = nums.length;
  while (start < end) {
    const mid = (start + end) >> 1;
    const minNumber = nums[mid];

    if (minNumber === target) {
      return mid;
    } else if (minNumber > target) {
      // 向后找
      end = mid;
    } else {
      start = mid + 1;
    }
  }

  return ans;
}

export {};
